<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="设置权益卡" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="设置权益卡:" prop="equity_id">
        <el-select v-model="form.equity_id" filterable clearable placeholder="请选择" style="width: 370px;">
          <el-option key="0" label="无权益卡" value="0" />
          <el-option
            v-for="item in equityCard"
            :key="item.equity_id"
            :label="item.equity_name"
            :value="item.equity_id" />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateEquityCard } from '@/api/mall/customer'
export default {
  components: { },
  data() {
    return {
      equityCard: [],
      loading: false, dialog: false,
      form: {
        equity_id: '',
        ids: []
      },
      rules: {
        equity_id: [
          { required: true, message: '请选择权益卡', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 表单验证
      this.$refs['form'].validate((valid) => {
        // 通过
        if (valid) {
          this.doAdd()
        }
      })
    },
    doAdd() {
      this.loading = true
      updateEquityCard(this.form).then(() => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(() => {
        this.loading = false
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        equity_id: ''
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
